<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>校园智慧灯光系统</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }
        
        body {
            background: linear-gradient(135deg, #1a2a6c, #b21f1f, #1a2a6c);
            color: #fff;
            min-height: 100vh;
            padding: 20px;
            overflow-x: hidden;
        }
        
        .container {
            max-width: 1200px;
            margin: 0 auto;
        }
        
        header {
            text-align: center;
            padding: 30px 0;
            margin-bottom: 30px;
            animation: fadeIn 1s ease-out;
        }
        
        h1 {
            font-size: 3.5rem;
            margin-bottom: 15px;
            text-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
            background: linear-gradient(90deg, #ff9d00, #ffffff);
            -webkit-background-clip: text;
            background-clip: text;
            color: transparent;
        }
        
        .subtitle {
            font-size: 1.3rem;
            max-width: 800px;
            margin: 0 auto;
            line-height: 1.6;
            color: #e0e0ff;
        }
        
        .system-container {
            display: flex;
            flex-wrap: wrap;
            gap: 30px;
            margin-bottom: 40px;
        }
        
        .classroom-section, .logic-section {
            flex: 1;
            min-width: 300px;
            background: rgba(0, 0, 30, 0.7);
            border-radius: 20px;
            padding: 25px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
            backdrop-filter: blur(10px);
            border: 1px solid rgba(100, 150, 255, 0.3);
        }
        
        .section-title {
            font-size: 1.8rem;
            margin-bottom: 20px;
            display: flex;
            align-items: center;
            gap: 10px;
            color: #ff9d00;
        }
        
        .classroom {
            position: relative;
            height: 300px;
            background: linear-gradient(to bottom, #2c3e50, #1c2833);
            border-radius: 15px;
            overflow: hidden;
            box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.8);
            margin-bottom: 20px;
        }
        
        .light {
            position: absolute;
            top: 20px;
            left: 50%;
            transform: translateX(-50%);
            width: 80px;
            height: 80px;
            border-radius: 50%;
            background: #333;
            box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
            transition: all 0.5s ease;
            z-index: 10;
        }
        
        .light.lit {
            background: radial-gradient(circle, #ffffaa, #ff9d00);
            box-shadow: 0 0 50px #ff9d00, 0 0 100px rgba(255, 157, 0, 0.5);
        }
        
        .light-rays {
            position: absolute;
            top: 80px;
            left: 50%;
            transform: translateX(-50%);
            width: 300px;
            height: 200px;
            background: radial-gradient(ellipse at center, rgba(255, 200, 0, 0.2) 0%, transparent 70%);
            opacity: 0;
            transition: opacity 0.5s ease;
        }
        
        .light.lit + .light-rays {
            opacity: 1;
        }
        
        .desks {
            position: absolute;
            bottom: 20px;
            width: 100%;
            display: flex;
            justify-content: space-around;
        }
        
        .desk-row {
            display: flex;
            gap: 20px;
        }
        
        .desk {
            width: 50px;
            height: 30px;
            background: #8b5a2b;
            border-radius: 5px;
            position: relative;
        }
        
        .desk:before {
            content: '';
            position: absolute;
            width: 40px;
            height: 40px;
            background: #5d4037;
            border-radius: 3px;
            top: -40px;
            left: 5px;
        }
        
        .human {
            position: absolute;
            bottom: 60px;
            left: 50%;
            transform: translateX(-50%);
            font-size: 3rem;
            transition: all 0.8s ease;
            z-index: 5;
        }
        
        .human.outside {
            left: -100px;
            bottom: 40px;
        }
        
        .status {
            display: flex;
            justify-content: space-around;
            margin: 20px 0;
        }
        
        .status-box {
            text-align: center;
            padding: 15px;
            border-radius: 10px;
            background: rgba(0, 20, 50, 0.6);
            width: 45%;
        }
        
        .status-title {
            font-size: 1.2rem;
            margin-bottom: 10px;
            color: #4fc3f7;
        }
        
        .status-value {
            font-size: 1.8rem;
            font-weight: bold;
        }
        
        .controls {
            display: flex;
            justify-content: center;
            gap: 20px;
            margin-top: 20px;
        }
        
        .btn {
            padding: 12px 30px;
            font-size: 1.1rem;
            border: none;
            border-radius: 50px;
            cursor: pointer;
            transition: all 0.3s ease;
            font-weight: bold;
            display: flex;
            align-items: center;
            gap: 8px;
        }
        
        .enter-btn {
            background: linear-gradient(to right, #00c853, #009624);
            color: white;
        }
        
        .exit-btn {
            background: linear-gradient(to right, #ff5252, #b33939);
            color: white;
        }
        
        .btn:hover {
            transform: translateY(-3px);
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
        }
        
        .btn:active {
            transform: translateY(1px);
        }
        
        .logic-diagram {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 200px;
            margin: 30px 0;
            position: relative;
        }
        
        .component {
            padding: 20px;
            border-radius: 10px;
            text-align: center;
            background: rgba(30, 40, 100, 0.7);
            position: relative;
            z-index: 2;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
        }
        
        .sensor {
            border: 2px solid #4fc3f7;
        }
        
        .not-gate {
            border: 2px solid #ff9d00;
            font-family: monospace;
            font-size: 1.5rem;
            font-weight: bold;
        }
        
        .lamp {
            border: 2px solid #00c853;
        }
        
        .component-value {
            font-size: 1.8rem;
            margin-top: 10px;
            font-weight: bold;
        }
        
        .wire {
            position: absolute;
            height: 4px;
            background: #aaa;
            z-index: 1;
        }
        
        .wire.active {
            background: #00c853;
            box-shadow: 0 0 8px #00c853;
        }
        
        .truth-table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 20px;
            background: rgba(0, 10, 30, 0.6);
            border-radius: 10px;
            overflow: hidden;
        }
        
        .truth-table th {
            background: rgba(0, 50, 100, 0.7);
            padding: 15px;
            text-align: center;
        }
        
        .truth-table td {
            padding: 12px;
            text-align: center;
            border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        }
        
        .truth-table tr:last-child td {
            border-bottom: none;
        }
        
        .highlight {
            background: rgba(255, 215, 0, 0.2);
            color: #ffd700;
            font-weight: bold;
        }
        
        .explanation {
            background: rgba(0, 20, 50, 0.7);
            border-radius: 15px;
            padding: 25px;
            margin-top: 40px;
            border-left: 5px solid #ff9d00;
        }
        
        .explanation h2 {
            margin-bottom: 20px;
            color: #ff9d00;
        }
        
        .explanation p {
            line-height: 1.8;
            margin-bottom: 15px;
        }
        
        .formula {
            font-family: monospace;
            font-size: 1.4rem;
            background: rgba(0, 0, 0, 0.3);
            padding: 15px;
            border-radius: 8px;
            margin: 20px 0;
            text-align: center;
            border: 1px solid #ff9d00;
        }
        
        footer {
            text-align: center;
            padding: 30px 0;
            margin-top: 40px;
            color: #a0a0ff;
            border-top: 1px solid rgba(100, 150, 255, 0.3);
        }
        
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(20px); }
            to { opacity: 1; transform: translateY(0); }
        }
        
        @media (max-width: 768px) {
            .system-container {
                flex-direction: column;
            }
            
            h1 {
                font-size: 2.5rem;
            }
            
            .subtitle {
                font-size: 1.1rem;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <header>
            <h1><i class="fas fa-lightbulb"></i> 校园智慧灯光系统</h1>
            <p class="subtitle">基于非门逻辑的节能照明系统：当教室有人时灯亮，无人时灯自动关闭。系统通过传感器检测人员状态，利用非门电路控制灯光。</p>
        </header>
        
        <div class="system-container">
            <div class="classroom-section">
                <h2 class="section-title"><i class="fas fa-chalkboard"></i> 教室场景模拟</h2>
                
                <div class="classroom">
                    <div class="light" id="classroom-light"></div>
                    <div class="light-rays"></div>
                    
                    <div class="human" id="human">
                        <i class="fas fa-male"></i>
                    </div>
                    
                    <div class="desks">
                        <div class="desk-row">
                            <div class="desk"></div>
                            <div class="desk"></div>
                            <div class="desk"></div>
                        </div>
                        <div class="desk-row">
                            <div class="desk"></div>
                            <div class="desk"></div>
                            <div class="desk"></div>
                        </div>
                    </div>
                </div>
                
                <div class="status">
                    <div class="status-box">
                        <div class="status-title">人员状态</div>
                        <div class="status-value" id="human-status">无人</div>
                    </div>
                    <div class="status-box">
                        <div class="status-title">灯光状态</div>
                        <div class="status-value" id="light-status">关闭</div>
                    </div>
                </div>
                
                <div class="controls">
                    <button class="btn enter-btn" id="enter-btn">
                        <i class="fas fa-door-open"></i> 进入教室
                    </button>
                    <button class="btn exit-btn" id="exit-btn">
                        <i class="fas fa-door-closed"></i> 离开教室
                    </button>
                </div>
            </div>
            
            <div class="logic-section">
                <h2 class="section-title"><i class="fas fa-microchip"></i> 逻辑控制电路</h2>
                
                <div class="logic-diagram">
                    <div class="component sensor">
                        <div>人体传感器</div>
                        <div class="component-value" id="sensor-output">1</div>
                    </div>
                    
                    <div class="wire" id="wire1" style="width: 80px; left: 180px; top: 100px;"></div>
                    
                    <div class="component not-gate">
                        <div>非门 (NOT)</div>
                        <div class="component-value" id="not-output">0</div>
                    </div>
                    
                    <div class="wire" id="wire2" style="width: 80px; left: 380px; top: 100px;"></div>
                    
                    <div class="component lamp">
                        <div>教室灯光</div>
                        <div class="component-value" id="lamp-output">0</div>
                    </div>
                </div>
                
                <table class="truth-table">
                    <thead>
                        <tr>
                            <th>人员状态</th>
                            <th>传感器输出 (S)</th>
                            <th>非门输出 (¬S)</th>
                            <th>灯光状态 (L)</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>有人 (1)</td>
                            <td>0</td>
                            <td>1</td>
                            <td>亮 (1)</td>
                        </tr>
                        <tr id="current-state">
                            <td>无人 (0)</td>
                            <td>1</td>
                            <td>0</td>
                            <td>灭 (0)</td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
        
        <div class="explanation">
            <h2><i class="fas fa-brain"></i> 系统工作原理</h2>
            <p>智慧灯光系统使用反向逻辑传感器结合非门电路实现智能控制：</p>
            
            <div class="formula">
                L = ¬S = ¬(¬P) = P
            </div>
            
            <p><strong>1. 传感器设计：</strong> 使用特殊的人体传感器，当检测到有人时输出低电平(0)，无人时输出高电平(1)。</p>
            <p><strong>2. 非门控制：</strong> 传感器信号输入非门(NOT Gate)，非门对输入信号进行取反操作。</p>
            <p><strong>3. 灯光驱动：</strong> 非门输出直接控制灯光驱动电路：</p>
            <ul>
                <li>输入0（有人）→ 非门输出1 → 灯亮</li>
                <li>输入1（无人）→ 非门输出0 → 灯灭</li>
            </ul>
            <p><strong>4. 最终结果：</strong> 灯光状态L直接反映教室是否有人（L = P），实现"有人灯亮，无人灯灭"的智能控制。</p>
        </div>
        
        <footer>
            <p>校园智慧灯光系统 | 基于非门逻辑的节能解决方案 | © 2023 智能校园技术</p>
        </footer>
    </div>
    
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            const classroomLight = document.getElementById('classroom-light');
            const human = document.getElementById('human');
            const enterBtn = document.getElementById('enter-btn');
            const exitBtn = document.getElementById('exit-btn');
            const humanStatus = document.getElementById('human-status');
            const lightStatus = document.getElementById('light-status');
            const sensorOutput = document.getElementById('sensor-output');
            const notOutput = document.getElementById('not-output');
            const lampOutput = document.getElementById('lamp-output');
            const wire1 = document.getElementById('wire1');
            const wire2 = document.getElementById('wire2');
            const currentStateRow = document.getElementById('current-state');
            
            let isOccupied = false;
            
            // 初始状态：无人
            updateSystem();
            
            // 进入教室按钮事件
            enterBtn.addEventListener('click', function() {
                isOccupied = true;
                updateSystem();
            });
            
            // 离开教室按钮事件
            exitBtn.addEventListener('click', function() {
                isOccupied = false;
                updateSystem();
            });
            
            function updateSystem() {
                // 更新人员状态
                if (isOccupied) {
                    human.classList.remove('outside');
                    humanStatus.textContent = '有人';
                    humanStatus.style.color = '#00c853';
                } else {
                    human.classList.add('outside');
                    humanStatus.textContent = '无人';
                    humanStatus.style.color = '#ff5252';
                }
                
                // 计算传感器输出（反向逻辑）
                const sensorValue = isOccupied ? 0 : 1;
                sensorOutput.textContent = sensorValue;
                sensorOutput.style.color = sensorValue === 0 ? '#00c853' : '#ff5252';
                
                // 计算非门输出
                const notValue = sensorValue === 0 ? 1 : 0;
                notOutput.textContent = notValue;
                notOutput.style.color = notValue === 1 ? '#00c853' : '#ff5252';
                
                // 更新灯光状态
                if (notValue === 1) {
                    classroomLight.classList.add('lit');
                    lightStatus.textContent = '开启';
                    lightStatus.style.color = '#ff9d00';
                    lampOutput.textContent = '1';
                    lampOutput.style.color = '#00c853';
                } else {
                    classroomLight.classList.remove('lit');
                    lightStatus.textContent = '关闭';
                    lightStatus.style.color = '#aaa';
                    lampOutput.textContent = '0';
                    lampOutput.style.color = '#ff5252';
                }
                
                // 更新电线状态
                wire1.classList.toggle('active', sensorValue === 0);
                wire2.classList.toggle('active', notValue === 1);
                
                // 更新真值表高亮
                if (isOccupied) {
                    currentStateRow.innerHTML = `
                        <td class="highlight">有人 (1)</td>
                        <td class="highlight">0</td>
                        <td class="highlight">1</td>
                        <td class="highlight">亮 (1)</td>
                    `;
                } else {
                    currentStateRow.innerHTML = `
                        <td>无人 (0)</td>
                        <td>1</td>
                        <td>0</td>
                        <td>灭 (0)</td>
                    `;
                }
            }
        });
    </script>
</body>
</html>